Chapter 9 | Computational Thinking
9.1 Computational Thinking
Computational thinking is a problem solving process where a number of steps are taken in order to reach a solution.
Abstraction
-
Abstraction involves removing (filtering out) unnecessary data and keeping only necessary data.
-
The solution is simplified so easier to implement
-
The system is tailored to the need of the user
-
An algorithm is an abstraction of a process that takes inputs, executes a sequence of steps, and produces outputs
Decomposition
- Decomposition means breaking down tasks into smaller parts to make it easier to solve. this is also known as stepwise refinement
- This can lead to structured programming using procedures and functions with parameters
- Can be represented using top-down diagrams:
9.2 Algorithms
- An algorithm is a solution to a problem expressed as a sequence of defined steps, and is done to perform a
- A good algorithm yields correct results, takes up very little memory, executes as fast as possible, and is concise, elegant, and easy to understand
Ways of representing algorithms
Structured english:
- A subset of the english language. consists of command statements
- Example structured english:
- Input a number
- Subtract 2 from the number
- Output the number
Pseudocode:
- Using keywords and identifiers to describe an algorithm. Resembles a programming language without following particular syntax; focuses on logic
-
Example pseudocode:
- INPUT Num
- Num ← Num - 2
- OUTPUT NUM
Flowchart:
- Consists of specific shapes linked together to represent sequential steps of an algorithm
Basic algorithm constructs:
- Assignment: An identifier is given a value or the value of a given identifier is changed
- Sequence: A number of steps are performed in order one after the other
- Selection: Choice of paths in a program (different steps are performed) depending on a condition. Selection is non-sequential
- Repetition: A sequence of steps is performed a repeated number of times. Also called iteration or looping